package com.zzyl.controller.nursing;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanServer;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 31043
 * @Description: 护理计划controller
 * @Date: 2024/1/5 AM 10:19
 * @Version: 1.0
 */
@Api(tags = "护理计划接口")
@RestController
@RequestMapping("/nursing/plan")
public class NursingPlanController extends BaseController {

    @Autowired
    private NursingPlanServer nursingPlanService;


    /**
     * 查询所有启动的计划
     */
    @GetMapping
    @ApiOperation("查询所有护理计划(启用)")
    public ResponseResult<List<NursingPlanVo>> queryAllStatus() {
        List<NursingPlanVo> nursingPlanVos = nursingPlanService.queryAllStatus();
        return success(nursingPlanVos);
    }

    /**
     * 分页查询护理计划
     */
    @GetMapping("/search")
    @ApiOperation("条件分页查询护理计划")
    public ResponseResult<NursingPlanVo> queryAllPage(
            @ApiParam("护理计划名称") @RequestParam(value = "name", required = false) String name,
            @ApiParam("护理计划状态") @RequestParam(value = "status", required = false) Integer status,
            @ApiParam("页码（默认为1）") @RequestParam(value = "pageNum", required = true) Integer pageNum,
            @ApiParam("每页大小（默认为10）") @RequestParam(value = "pageSize", required = true) Integer pageSize
    ) {
        PageResponse<NursingPlanVo> nursingPlanVoPageResponse = nursingPlanService.queryAllPage(name, status, pageNum, pageSize);
        return success(nursingPlanVoPageResponse);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> queryById(
            @ApiParam(value = "护理计划id", name = "id") @PathVariable("id") Long id
    ) {
        NursingPlanVo nursingPlanVo = nursingPlanService.queryById(id);
        System.out.println(nursingPlanVo);
       return success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult insertNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.insert(nursingPlanDto);
        return success();
    }

    @PutMapping
    @ApiOperation("更新护理计划")
    public ResponseResult updateNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.update(nursingPlanDto);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除计划")
    public ResponseResult deleteNursingPlan(
            @ApiParam(value = "护理计划id", name="id") @PathVariable(value = "id",required = true) Long id
    ){
        nursingPlanService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用")
    public ResponseResult updateNursingPlanStatus(
            @ApiParam(value = "护理计划id", name="id") @PathVariable(value = "id",required = true) Long id,
            @ApiParam(value = "护理计划状态 0 禁用 1 启用", name="status") @PathVariable(value = "status",required = true) Long status
    ){
        nursingPlanService.updateStatus(id,status);
        return success();
    }


}
